package org.bsc.mgwt.client.widget.experimental;

import com.google.gwt.uibinder.client.UiChild;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.googlecode.mgwt.ui.client.theme.base.LayoutCss;
import com.googlecode.mgwt.ui.client.widget.LayoutPanel;

/**
 * 
 * @author bsorrentino
 *
 */
public class InputField extends LayoutPanel {

	Label label;
	Widget widget;
	
	public InputField() {
		super();
	}
	
	public InputField(LayoutCss css) {
		super(css);
	}
	
	@UiChild(limit = 1, tagname = "label")
	public void setLabel(Label label) {
		if( null==label) throw new IllegalArgumentException("label is null!");
		this.label = label;
		this.label.getElement().setAttribute("mtype", "label");
	}

	@UiChild(limit = 1, tagname = "input")
	public void setWidget(Widget w) {
		if( null==label) throw new IllegalArgumentException("widget is null!");
		this.widget = w;
		this.widget.getElement().setAttribute("mtype", "input");

	}
	public Label getLabel() {
		return label;
	}
	public Widget getWidget() {
		return widget;
	}
	
	@Override
	protected void onAttach() {
		super.onAttach();
		
		if( label != null ) add( label );
		if( widget !=null ) add( widget );
	}

	@Override
	protected void onDetach() {
		super.onDetach();
		
		if( label != null ) remove( widget );
		if( widget !=null ) remove( label );
	}
	
}
